<template>
	<view :class="[empty ? '' : 'padding-lr-sm']">
		
		<!-- 空白页 -->
		<use-empty v-if="empty" e-style="round" e-type="cart" :btn-tip="false" tip="暂无记录"></use-empty>
		
		<view v-else class="padding bg-main border-radius margin-top-sm pos-r" v-for="(item, idx) in datas" :key="idx">
			<view class="dflex-b ">
				<view class="dflex">
					<view class="">
						<view class="fwbd">
							编号:{{ item.applyId }}
						</view>
						<view class="fs-xxs ft-dark">
							买方手续费:¥{{ item.totalFee }},
							卖方手续费:¥{{ item.tradeFee_S }}
						</view>
						<view class="fs-xxs ft-dark">
							{{ $api.format(item.createTime, 'yyyy-MM-dd hh:mm') }}
						</view>
					</view>
				</view>
				<view class="dflex-c dflex-flow-c">
					<view class=""><view class="fwb">{{item.quantity}}✖{{item.price }}￥</view></view>
					<view class="bg-base border-radius fs-xs" @click="confirmOrder(item)" style="padding: 4rpx 15rpx;">
						确认提现
					</view>
				</view>
			</view>
			<view class="bg-base fs-xxs pos-a pos-top pos-right" style="border-bottom-left-radius: 20rpx; padding: 2rpx 10rpx;">
				{{zidian[item.status]}}
			</view>
		</view>
		
		<!-- 操作菜单 -->
		<use-action-sheet v-model="actionSheetShow" :list="actionSheetList" :tips="actionSheetTips"
			@click="actionSheetClick" @close="actionSheetClose"></use-action-sheet>
	</view>
</template>

<script>
	import {unconfirmed_list,protocol_trade_confirm,get_account} from "../../../js_sdk/apis/user.js"
	import { address_list } from "../../../js_sdk/apis/address.js"
	export default {
		data() {
			return {
				empty: false,
				zidian:{
					0:"申请",
					1:"市场审核通过",
					2:"市场审核驳回",
					3:"用户确认中",
					4:"用户已确认",
					5:"用户已拒绝",
					6:"已到期"
				},
				applyId:"",
				actionSheetShow: false,
				actionSheetList: [],
				actionSheetTips: {
					text: "选择提现银行卡",
					color: "#9a9a9a",
					size: 24
				},
				tempData:{},
				datas: [],
				addrData:null
			};
		},
		onLoad(options) {
			this.loadData();
			address_list().then(res=>{
				this.addrData=res.data.content.filter(v=>v.isDefault)[0]||res.data.content[0]
				if(!addrData){
					uni.showModal({
						title:"提示",
						content:"请先完善收货地址。",
						success: () => {
							uni.navigateTo({
								url:"../address/address"
							})
						}
					})
				}
			})
		},
		methods: {
			// 打开操作菜单
			// 关闭操作菜单
			actionSheetClose() {
				console.log(this.actionSheetShow);
			},
			// 点击操作菜单
			actionSheetClick(index) {
				let temp=this.actionSheetList[index].data
				console.log(temp)
				let sendData={
					applyId:this.applyId,
					commodityId:this.tempData.commodityId,
					quantity:this.tempData.quantity,
					protocolTradeConfirmVO:{
						"addressId":this.addrData.addressId,
						"applyId":this.applyId,
						"bankId":temp.id,
						"bankNO":temp.bank,
						"payType":0,
						"tradeType":0,
						"type":1,
					}	
				}
				protocol_trade_confirm(sendData).then(res=>{
					this.loadData();
					uni.showModal({
						title:"成功",
						content:"确认成功"
					})
				})
			},
			confirmOrder(e){
				this.tempData=e
				get_account().then(res=>{
					this.actionSheetShow = true;
					this.actionSheetList = res.data.content.map(v=>{return {
						text:v.showAccount+"("+v.bankName+")",
						color: "#333",
						data:v
					}})
				})
				this.applyId=e.applyId
			},
			// 加载商品，下拉刷新|上拉加载
			async loadData() {
				unconfirmed_list({offset:1000}).then(res => {
					console.log(res)
					this.datas=res.data&&res.data.content&&res.data.content.list
					this.empty = !(this.datas && this.datas.length > 0);
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f5f5;
	}
	/* 订单状态区 */
	.navbar-area {
		white-space: nowrap;
	}
	
	.state-area {
		height: 7vh;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
	}
	
	.nav-item {
		flex: 1;
	
		&.active {
			&:after {
				content: '';
				position: absolute;
				left: 50%;
				transform: translate(-50%);
				bottom: 0;
				width: 44px;
				height: 0;
				border-bottom: 2px solid $base-color;
			}
		}
	}
	
</style>
